package com.yycx.dbr.boot.admin.handler;

import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.base.handler.AdminUserInfoHandler;
import com.yycx.common.security.OpenHelper;
import com.yycx.common.security.OpenUser;
import com.yycx.module.admin.provider.service.BaseRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author Administrator
 */
@Component
public class MyAdminUserInfoHandler implements AdminUserInfoHandler {


    @Override
    public void initOpenUser(OpenUser openUser, Map attrs) {
        EntityMap roleInfo = new EntityMap();
        Boolean customFlag = OpenHelper.hasRole("ROLE_KJ", "ROLE_NQBZ", "ROLE_CGBZ", "ROLE_CWBZ", "ROLE_ZJL", "ROLE_CG", "ROLE_JSKJ_LD", "ROLE_NQBZ_LD", "ROLE_CGBZ_LD", "ROLE_CWBZ_LD", "ROLE_ZJL_LD", "ROLE_CG_LD");
        attrs.put("customFlag", customFlag);

        //是否允许核算
        Boolean isCw = OpenHelper.hasRole("ROLE_CW_JSY", "ROLE_CW_FHY", "ROLE_CW_JSBX", "ROLE_CW_ZJ");
        attrs.put("isCw", isCw);
        Boolean calculate = OpenHelper.hasRole("ROLE_XS_BZ", "ROLE_SW_FHY","ROLE_SW_JSY", "ROLE_SW_HSY","ROLE_SW_FHY","ROLE_SW_SKY", "ROLE_CW_JSY", "ROLE_CW_FHY");
        attrs.put("calculate", calculate);
        //销售角色
        Boolean xs = OpenHelper.hasRole("ROLE_XS_KPY", "ROLE_XS_JSY","ROLE_XS_BZ","ROLE_XS_FHY");
        //市场组角色
        Boolean sw = OpenHelper.hasRole("ROLE_SW_JSY","ROLE_SW_SKY","ROLE_SW_HSY","ROLE_SW_FHY","ROLE_SW_HTZY");

        //领导角色
        Boolean isLd = OpenHelper.hasRole("ROLE_CW_JSBX","ROLE_SW_SCZZ","ROLE_SW_BMZJ","ROLE_SW_SKY");

        //订单审核查看角色
        Boolean isDc = OpenHelper.hasRole("ROLE_CW_JSBX");
        //合同专员
        Boolean isHtzy = OpenHelper.hasRole("ROLE_SW_HTZY");

        //费用核算查看角色
        Boolean isFc = OpenHelper.hasRole("ROLE_CW_JSBX","ROLE_SW_HSY","ROLE_SW_FHY","ROLE_SW_SKY","ROLE_XS_BZ");


        //商务中心
        Boolean isHs = OpenHelper.hasRole("ROLE_SW_DCZ","ROLE_SW_DCZZ","ROLE_SW_HTZY");
        //出纳角色
        Boolean isCn = OpenHelper.hasRole("ROLE_HZ_CN","ROLE_FLP_CN");

        roleInfo.put("isXs", xs);
        roleInfo.put("isSw", sw);
        roleInfo.put("isCw", isCw);
        roleInfo.put("isLd", isLd);
        roleInfo.put("isCn", isCn);
        roleInfo.put("isDc", isDc);
        roleInfo.put("isFc", isFc);
        roleInfo.put("isHs", isHs);
        roleInfo.put("isHtzy", isHtzy);
        roleInfo.put("customFlag", customFlag);
        roleInfo.put("calculate", calculate);
        attrs.put("roleInfo", roleInfo);
    }
}
